<?php
namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Game\Generator\CharacterGenerator;
use App\Globals;

class GenerateCharacter extends Command
{
    protected function configure()
    {
        $this
            ->setName('generate:character')
            ->setDescription('Generate character')
            ->addArgument('type', InputArgument::REQUIRED, 'Character type (pers, bot)')
            ->addArgument('name', InputArgument::REQUIRED, 'Character name')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $name = $input->getArgument('name');
        $type = $input->getArgument('type');
        $gen = new CharacterGenerator();
        $char = $gen->generate($type, array());
        $char->setName($name);

        $em = Globals::init()->getEntityManager();

        $em->persist($char);
        $em->flush();

        $text = sprintf('<info>Character "%s" with id=%s created</info>', $char->getName(), $char->getId());

        $output->writeln($text);
    }
}
